class = require'lib.middleclass.trunk.middleclass'
Stateful = require'lib.stateful.trunk.stateful'
lume = require'lib.lume.trunk.lume'
JSON = require'lib.JSON'
require'lib.AnAL'
require'lib.loveframes.trunk'
require'src.game'


function love.load()
	game = Game:new()
	
end

function love.update(dt)
	dt = math.min(0.01666667, dt)
	game:update(dt)
	loveframes.update(dt)
end

function love.draw()
	game:draw()
	loveframes.draw()
end

function love.keypressed(key, isRepeat)
	game:keypressed(key, isRepeat)
	loveframes.keypressed(key, isRepeat)
end

function love.keypreleased(key)
	game:keyreleased(key)
	loveframes.keyreleased(key)
end

function love.mousepressed(x, y, button)
	game:mousepressed(x, y, button)
	loveframes.mousepressed(x, y, button)
end

function love.mousereleased(x, y, button)	
	game:mousereleased(x, y, button)
	loveframes.mousereleased(x, y, button)
end

function love.textinput(text)
	loveframes.textinput(text)
end

function love.threaderror(thread, errorstr)
	print("Thread Error!\n" .. errorstr)
end

function love.quit()
	game:quit()
end

--[[
function table.val_to_str ( v )
  if "string" == type( v ) then
    v = string.gsub( v, "\n", "\\n" )
    if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then
      return "'" .. v .. "'"
    end
    return '"' .. string.gsub(v,'"', '\\"' ) .. '"'
  else
    return "table" == type( v ) and table.tostring( v ) or
      tostring( v )
  end
end

function table.key_to_str ( k )
  if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then
    return k
  else
    return "[" .. table.val_to_str( k ) .. "]"
  end
end

function table.tostring( tbl )
  local result, done = {}, {}
  for k, v in ipairs( tbl ) do
    table.insert( result, table.val_to_str( v ) )
    done[ k ] = true
  end
  for k, v in pairs( tbl ) do
    if not done[ k ] then
      table.insert( result,
        table.key_to_str( k ) .. "=" .. table.val_to_str( v ) )
    end
  end
  return "{" .. table.concat( result, "," ) .. "}"
end
]]